package com.ochnas.volunteersignup.domain;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.Transient;

@Embeddable
public class Time implements Serializable {
	@Transient
	private static SimpleDateFormat simpleTimeFormat = new SimpleDateFormat("hh:mm a");
	@Transient
	private static Calendar calendar = Calendar.getInstance();

	/**
	 * hourOfDay ranges from 0 to 23, where midnight is represented by 0.
	 */
	@Column(name = "TIME_HOUR_OF_DAY", nullable = false)
	private int hourOfDay;
	
	/**
	 * minutes ranges from 0 to 59.
	 */
	@Column(name = "TIME_MINUTES", nullable = false)
	private int minutes;
	
	/**
	 * No-argument constructor.
	 */
	public Time() {
		super();
	}
	
	/**
	 * Time-defined constructor.
	 * @param hourOfDay
	 * @param minutes
	 */
	public Time(int hourOfDay, int minutes) {
		super();
		this.hourOfDay = hourOfDay;
		this.minutes = minutes;
	}

	/**
	 * Method to return hour of the day
	 * @return int
	 */
	public int getHourOfDay() {
		return hourOfDay;
	}
	
	/**
	 * Method to set hour of the day
	 * @param hourOfDay
	 */
	public void setHourOfDay(int hourOfDay) {
		this.hourOfDay = hourOfDay;
	}
	
	/**
	 * Method to return minutes of the hour
	 * @return int
	 */
	public int getMinutes() {
		return minutes;
	}
	
	/**
	 * Method to set minutes of the hour
	 * @param minutes
	 */
	public void setMinutes(int minutes) {
		this.minutes = minutes;
	}

	@Override
	public String toString() {
		calendar.set(Calendar.HOUR_OF_DAY, getHourOfDay());
		calendar.set(Calendar.MINUTE, getMinutes());
		Date dateTime = calendar.getTime();
		return simpleTimeFormat.format(dateTime);
	}
	
}
